import requests
from config import url, headers_web


class CourseAnnouncement:
    def __init__(self):
        self.url = url
        self.headers = headers_web

    @classmethod
    def get_announcements_ByCourse(cls, url: str, params=None, headers=headers_web):
        """
        Summary:根据课程拿到所有的课程公告
        Description:根据课程拿到所有的课程公告
        :param url:
        :param params:
        :return:
        """
        url = url + "/teachingApi/api/v1/courseAnnouncement/getAnnouncementsByCourse"
        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def get_announcements_ByStudentID(cls, url: str, params=None, headers=headers_web, paramspath=None):
        """
        Summary:根据学生Id拿到所有的公告
        Description:调用方：1.云课堂学生web端—课程公告列表
        :param url:
        :param params:
        :param paramspath:
        :return:
        """
        url = url + f"/teachingApi/api/v1/courseAnnouncement/getAnnouncementsByUserId/{paramspath}"
        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def get_announcements_ByID_UserID(cls, url: str, params=None, headers=headers_web, paramspath=None):
        """
        Summary:根据课程公告Id和学生ID拿到此公告的详细信息
        Description:云课堂学生web端-云课堂课程公告
        :param url:
        :param params:
        :param paramspath:
        :return:
        """
        url = url + f"/teachingApi/api/v1/courseAnnouncement/getAnnouncementsByIdAndUserId/{paramspath}"
        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def get_announcements_ByannouncementsID(cls, url: str, params=None, headers=headers_web, paramspath=None):
        """
        Summary:根据课程公告Id拿到此公告的所有信息
        Description:根据课程公告Id拿到此公告的所有信息
        :param url:
        :param params:
        :param paramspath:
        :return:
        """
        url = url + f"/teachingApi/api/v1/courseAnnouncement/getAnnouncementsById/{paramspath}"
        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def get_announcementuser(cls, url: str, params=None, headers=headers_web):
        """
        Summary:获取课程公告通知人员详情
        Description:调用方：1.老师web端—查询课程公告人员查看详情
        :param url:
        :param params:
        :return:
        """
        url = url + "/teachingApi/api/v1/announcementuser/"
        r = requests.get(url=url, headers=headers, params=params)
        return r

    @classmethod
    def post_del_announcements(cls, url: str, params=None, headers=headers_web, json=None, paramspath=None):
        """
        Summary:删除课程公告
        Description:云课堂老师web端-云课堂课程公告
        :param url:
        :param params:
        :param headers:
        :param json:
        :param paramspath:
        :return:
        """
        url = url + f"/teachingApi/api/v1/courseAnnouncement/{paramspath}/del"
        r = requests.post(url=url, headers=headers, params=params, json=json)
        return r

    @classmethod
    def post_add_announcements(cls, url: str, params=None, headers=headers_web, json=None):
        """
        Summary:新增课程公告
        Description:调用方：1.老师web端—新增课程公告
        :param url:
        :param params:
        :param headers:
        :param json:
        :return:
        """
        url = url + "/teachingApi/api/v1/courseannouncement/"
        r = requests.post(url=url, headers=headers, params=params, json=json)
        return r

    @classmethod
    def post_announcements_status(cls, url: str, params=None, headers=headers_web, json=None, paramspath=None):
        """
        Summary:学生端修改查看状态
        Description:云课堂学生web端-云课堂课程公告
        :param url:
        :param params:
        :param headers:
        :param json:
        :param paramspath:
        :return:
        """
        url = url + f"/teachingApi/api/v1/courseAnnouncement/{paramspath}"
        r = requests.post(url=url, headers=headers, params=params, json=json)
        return r

    @classmethod
    def post_updatecourseannouncement(cls, url: str, params=None, headers=headers_web, json=None):
        """
        Summary:修改课程公告数据保存
        Description:调用方：1.老师web端—修改课程公告
        :param url:
        :param params:
        :param headers:
        :param json:
        :return:
        """
        url = url + "/teachingApi/api/v1/updatecourseannouncement/"
        r = requests.post(url=url, headers=headers, params=params, json=json)
        return r

    @classmethod
    def post_initialize(cls, url: str, params=None, headers=headers_web, json=None):
        """
        Summary:初始化课程公告发布人员信息
        Description:调用方：1.内部调用—teachingService课程公告定时发布任务调用
        :param url:
        :param params:
        :param headers:
        :param json:
        :return:
        """
        url = url + "/teachingApi/api/v1/courseannouncement/courseannouncementtimeinterval"
        r = requests.post(url=url, headers=headers, params=params, json=json)
        return r


if __name__ == '__main__':
    from common.hashlib_utils import hash_md5
    # import jsonpath
    valid_code13 = hash_md5("id=ff8081818a53c992018a5e34b5f2019f&signKey=123123")
    params = {
        "userId": "297ead2e80d9f9d20181d9791c623b5a",
        "validCode": valid_code13
    }
    resp = CourseAnnouncement.post_announcements_status(url=url, params=params,paramspath="ff8081818a53c992018a5e34b5f2019f")
    # announcement_ids = jsonpath.jsonpath(resp3.json()[1], "$.announcementUserList.[*].userName")
    # print(resp3.json())
    # print(announcement_ids)
